﻿using System;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using TakeFoodSystem.Entity;

namespace TakeFoodSystem
{
    /// <summary>
    /// ViceScreen.xaml 的交互逻辑
    /// </summary>
    public partial class ViceScreen : Window
    {
        Timer timer = null;
        int count = 0;

        public ViceScreen()
        {
            InitializeComponent();

            timer = new Timer
            {
                Interval = 1000
            };

            // Hook up the Elapsed event for the timer. 
            timer.Elapsed += OnTimedEvent;

            // Have the timer fire repeated events (true is the default)
            timer.AutoReset = true;

            // Start the timer
            timer.Enabled = true;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // 设置全屏
            this.WindowState = WindowState.Normal;
            this.WindowStyle = WindowStyle.None;
            this.ResizeMode = ResizeMode.NoResize;
            //this.Topmost = true;

            count = Global.ObservableCollection.Count;
            lvTakeFood.ItemsSource = Global.ObservableCollection;
        }

        private void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
            Task task = new Task(new Action(delegate {
                lvTakeFood.Dispatcher.Invoke(new Action(delegate {
                    if (Global.IsRefresh)
                    {
                        lvTakeFood.ItemsSource = Global.ObservableCollection;
                    }
                }));
            }));
            task.Start();
        }
    }
}
